package com.yelobblog.yelobblog.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    // 一天
    private static final long MAX_AGE = 24 * 60 * 60;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")   // Apply the current CORS configuration to all requests under the current path
                // highlight-next-line
                .allowedOrigins("*") // Only allow requests from the domain lovelypepe.cn
//                .allowedOrigins("http://lovelypepe.cn")
                .allowedMethods("*") // Allowed request methods, can specify specific ones, e.g., "GET", "POST", "PUT", "DELETE"
                .allowedHeaders("*") // Allowed request header types, can specify specific ones, e.g., "Content-Type", "Authorization"
                .maxAge(MAX_AGE);    // Set the maximum valid duration for requests. Within this duration, repeated requests will not send preflight requests
    }
}
